﻿using System;
using IQIGame.Onigao.Framework;

namespace IQIGame.Onigao.GamePlay
{
    public class PlayerSkillCommand : PlayerCommand
    {
        public int skillID;
        public bool cancel;

        public override EPlayerCommandType type => EPlayerCommandType.Skill;

        public void Initialize(int nSkillID, bool bCancel)
        {
            this.skillID = nSkillID;
            this.cancel = bCancel;
        }

        public override void Execute(UnitView entity)
        {
            var rOrderComp = entity.GetComponent<PlayerOrderComponent>(ETComponentType.PlayerOrderComponent);
            if (!this.cancel && this.skillID >= 0)
            {
                rOrderComp.Cast(this.skillID);
            }
            else
            {
                rOrderComp.Cancel(this.skillID);
            }
        }

        public override void OnReset()
        {
            base.OnReset();
            this.skillID = 0;
            this.cancel = false;
        }

        public override void Free()
        {
            ClassPool.Put(this);
        }
    }
}